x = int(input())
y=0
y2=0
y3=0
y4=0
a1 = x//1000
a2 = (x%1000)//100
a3 = (x%100)//10
a4 = x%10
b1 = x//100
b2 = (x%1000)//10
b3 = x%100
c1 = x//10
c2 = x%1000
if x//1000 == 0 or x<0:
    print(0)
if x//1000 != 0:
    for i in range(2, x, 1):
        if x%i == 0:
            y = y + 1
    if y == 0:
        if x > 0:
            print(x)
    if y != 0:
        y = 0
        for i in range(2, c1, 1):
            if c1%i == 0:
                y = y + 1
        for i in range(2, c2, 1):
            if c2%i == 0:
                y2 = y2 + 1
        if y == 0 and y2 !=0:
            if c1 > 0:
                print(c1)
        if y != 0 and y2 == 0:
            if c2 > 0:
                print(c2)
        if y == 0 and y2 == 0:
            if c1 >= c2:
                if c1 > 0:
                    print(c1)
            else:
                if c2 > 0:
                    print(c2)
        if y!=0 and y2!=0:
            y = 0
            y2 = 0
            for i in range(2, b1, 1):
                if b1%i == 0:
                    y = y + 1
            for i in range(2, b2, 1):
                if b2%i == 0:
                    y2 = y2 + 1
            for i in range(2, b3, 1):
                if b3%i == 0:
                    y3 = y3 + 1
            if y == 0 and y2!=0 and y3!=0:
                if b1 > 0:
                    print(b1)
            if y!=0 and y2==0 and y3!=0:
                if b2 > 0:
                    print(b2)
            if y!= 0 and y2!=0 and y3 == 0:
                if b3 > 0:
                    print(b3)
            if y == 0 and y2 == 0 and y3 != 0:
                if b1 >= b2:
                    if b1 > 0:
                        print(b1)
                else:
                    if b2 > 0:
                        print(b2)
            if y != 0 and y2 == 0 and y3 == 0:
                if b2 >= b3:
                    if b2 > 0:
                        print(b2)
                else:
                    if b3 > 0:
                        print(b3)
            if y == 0 and y2 != 0 and y3 == 0:
                if b1 >= b3:
                    if b1 > 0:
                        print(b1)
                else:
                    if b3 > 0:
                        print(b3)
            if y == 0 and y2 == 0 and y3 == 0:
                if b1 >= b2 and b1 >= b3:
                    if b1 > 0:
                        print(b1)
                if b2 > b1 and b2 > b3:
                    if b2 > 0:
                        print(b2)
                if b3 > b1 and b3 > b2:
                    if b3 > 0:
                        print(b3)
            if y != 0 and y2 != 0 and y3 != 0:
                y = 0
                y2 = 0
                y3 = 0
                if a1 == 2 or a1 == 3 or a1 == 5 or a1 == 7:
                    y = y + 1
                if a2 == 2 or a2 == 3 or a2 == 5 or a2 == 7:
                    y2 = y2 + 1
                if a3 == 2 or a3 == 3 or a3 == 5 or a3 == 7:
                    y3 = y3 + 1
                if a4 == 2 or a4 == 3 or a4 == 5 or a4 == 7:
                    y4 = y4 + 1
                if y > 0 and y2 > 0 and y3 > 0 and y4 > 0:
                    if a1 >= a2 and a1 >= a3 and a1 >= a4:
                        if a1 > 0:
                            print(a1)
                    if a2 > a1 and a2 > a3 and a2 > a4:
                        if a2 > 0:
                            print(a2)
                    if a3 > a1 and a3 > a2 and a3 > a4:
                        if a3 > 0:
                            print(a3)
                    if a4 > a1 and a4 > a2 and a4 > a3:
                        if a4 > 0:
                            print(a4)
                if y > 0 and y2 == 0 and y3 == 0 and y4 == 0:
                    if a1 > 0:
                        print(a1)
                if y == 0 and y2 > 0 and y3 == 0 and y4 == 0:
                    if a2 > 0:
                        print(a2)
                if y == 0 and y2 == 0 and y3 > 0 and y4 == 0:
                    if a3 > 0:
                        print(a3)
                if y == 0 and y2 == 0 and y3 == 0 and y4 > 0:
                    if a4 > 0:
                        print(a4)
                if y > 0 and y2 > 0 and y3 > 0 and y4 == 0:
                    if a1 >= a2 and a1 >= a3:
                        if a1 > 0:
                            print(a1)
                    if a2 > a1 and a2 > a3:
                        if a2 > 0:
                            print(a2)
                    if a3 > a1 and a3 > a2:
                        if a3 > 0:
                            print(a3)
                if y == 0 and y2 > 0 and y3 > 0 and y4 > 0:    
                    if a2 >= a3 and a2 >= a4:
                        if a2 > 0:
                            print(a2)
                    if a3 > a2 and a3 > a4:
                        if a3 > 0:
                            print(a3)
                    if a4 > a2 and a4 > a3:
                        if a4 > 0:
                            print(a4)
                if y > 0 and y2 == 0 and y3 > 0 and y4 > 0:    
                    if a1 >= a3 and a1 >= a4:
                        if a1 > 0:
                            print(a1)
                    if a3 > a1 and a3 > a4:
                        if a3 > 0:
                            print(a3)
                    if a4 > a1 and a4 > a3:
                        if a4 > 0:
                            print(a4)
                if y > 0 and y2 > 0 and y3 == 0 and y4 > 0:
                    if a1 >= a2 and a1 >= a4:
                        if a1 > 0:
                            print(a1)
                    if a2 > a1 and a2 > a4:
                        if a2 > 0:
                            print(a2)
                    if a4 > a1 and a4 > a2:
                        if a4 > 0:
                            print(a4)
                if y > 0 and y2 > 0 and y3 == 0 and y4 == 0:
                    if a1 >= a2:
                        if a1 > 0:
                            print(a1)
                    else:
                        if a2 > 0:
                            print(a2)
                if y == 0 and y2 > 0 and y3 > 0 and y4 == 0:
                    if a2 >= a3:
                        if a2 > 0:
                            print(a2)
                    else:
                        if a3 > 0:
                            print(a3)
                if y == 0 and y2 == 0 and y3 > 0 and y4 > 0:    
                    if a3 >= a4:
                        if a3 > 0:
                            print(a3)
                    else:
                        if a4 > 0:
                            print(a4)
                if y == 0 and y2 > 0 and y3 == 0 and y4 > 0:  
                    if a2 >= a4:
                        if a2 > 0:
                            print(a2)
                    else:
                        if a4 > 0:
                            print(a4)
                if y > 0 and y2 == 0 and y3 > 0 and y4 == 0:    
                    if a1 >= a3:
                        if a1 > 0:
                            print(a1)
                    else:
                        if a3 > 0:
                            print(a3)
                if y > 0 and y2 == 0 and y3 == 0 and y4 > 0:    
                    if a1 >= a4:
                        if a1 > 0:
                            print(a1)
                    else:
                        if a4 > 0:
                            print(a4)
                if y == 0 and y2 == 0 and y3 == 0 and y4 == 0:
                    print(0)